from PythonProject.Data import Data
from PythonProject.algorithm import Calc
from xlutils import copy
import xlrd


class TestCalc():
    def testADD(self):
        data = Data().addData()
        calc = Calc()
        for i in data:
            result = calc.add(i[1],i[2])
            wb = xlrd.open_workbook('测试.xls')
            wb_c = copy.copy(wb)
            ws_c = wb_c.get_sheet(0)
            ws_c.write(i[0],4,result)
            if result==i[3]:
                ws_c.write(i[0],5,"通过")
            else:
                ws_c.write(i[0],5,"不通过")
            wb_c.save("测试.xls")
    def testSUB(self):
        data = Data().subData()
        calc = Calc()
        for i in data:
            result = calc.sub(i[1],i[2])
            wb = xlrd.open_workbook('测试.xls')
            wb_c = copy.copy(wb)
            ws_c = wb_c.get_sheet(1)
            ws_c.write(i[0],4,result)
            if result==i[3]:
                ws_c.write(i[0],5,"通过")
            else:
                ws_c.write(i[0],5,"不通过")
            wb_c.save("测试.xls")
    def testMUL(self):
        data = Data().mulData()
        calc = Calc()
        for i in data:
            result = calc.mul(i[1],i[2])
            wb = xlrd.open_workbook('测试.xls')
            wb_c = copy.copy(wb)
            ws_c = wb_c.get_sheet(2)
            ws_c.write(i[0],4,result)
            if result==i[3]:
                ws_c.write(i[0],5,"通过")
            else:
                ws_c.write(i[0],5,"不通过")
            wb_c.save("测试.xls")
    def testDIV(self):
        data = Data().divData()
        calc = Calc()
        for i in data:
            result = calc.div(i[1],i[2])
            wb = xlrd.open_workbook('测试.xls')
            wb_c = copy.copy(wb)
            ws_c = wb_c.get_sheet(3)
            ws_c.write(i[0],4,result)
            if result==i[3]:
                ws_c.write(i[0],5,"通过")
            else:
                ws_c.write(i[0],5,"不通过")
            wb_c.save("测试.xls")
TestCalc().testADD()
TestCalc().testSUB()
TestCalc().testMUL()
TestCalc().testDIV()